import 'package:flutter_test/flutter_test.dart';

class MyClass {
  int _aProperty = 0;

  int get aProperty => _aProperty;

  set aProperty(int value) {
    if (value >= 0) {
      _aProperty = value;
    }
  }
}

class MyClass2 {
  final List<int> _values = [];

  void addValue(int value) {
    _values.add(value);
  }

  // A computed property.
  int get count {
    return _values.length;
  }
}

class InvalidPriceException {}

class ShoppingCart {
  List<double> _prices = [];

  // Add a "total" getter here:
  double get total {
    return _prices.reduce((value, element) => value + element);
  }

  // Add a "prices" setter here:
  set prices(List<double> values) {
    values.any((element) => element < 0)
        ? throw InvalidPriceException()
        : _prices = values;
  }
}

main(List<String> args) {
  var a = ShoppingCart();
  a.prices = [-1.1, 2];
  print(a.total);
}
